#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>

@interface UIPickerView (MRPickerView)

@end

//组件===========================================================
@class MRPickerView;
@class MRPickerComponent;
typedef void(^ComponentHandler) (MRPickerComponent *component);

@interface MRPickerComponent : UIView <UIPickerViewDelegate, UIPickerViewDataSource>
{
	UIPickerView	*_picker;
	NSData			*_copyContent;
	
	BOOL			_isFloat, _isLoop;
	
	NSInteger		_lastRow;
	NSInteger		_lastIndex;
	ComponentHandler	_handler;
}

+ (instancetype)componentWithPickerView:(MRPickerView *)pickerView;
- (instancetype)initWithPickerView:(MRPickerView *)pickerView withLoop:(BOOL)loop;

@property (nonatomic, weak, readonly) MRPickerView	*pickerView;

@property (nonatomic, retain)	NSArray			*items;
- (void)addItem:(NSString *)item;

@property (nonatomic, readonly) MRLabel			*content;		//组件内容(只是用于文本属性复制，文本内容由组件决定)
@property (nonatomic, retain)   MRLabel			*unit;			//组件内容单位
@property (nonatomic) CGFloat		width;			//组件占用宽度百分比(0.0 ~ 1.0)， 默认-1由选择器决定

//
@property (nonatomic, readonly) NSString		*format;		//格式化后的格式字符串
@property (nonatomic, readonly) NSInteger		decimal;		//小数基数(0:内容为数组 1:没有小数 10:1位小数 100:2位小数)
@property (nonatomic, readonly) NSInteger		maxValue;
@property (nonatomic, readonly) NSInteger		minValue;

//组件索引
@property (nonatomic) NSInteger		index;			//当前所选索引
- (void)setIndex:(NSInteger)index animated:(BOOL)animated;

//范围值
@property (nonatomic) CGFloat		scale;			//当前缩放率(setRange时自动计算，用户可修改)
@property (nonatomic) NSInteger		value;			//当前值(最小值+当前索引，循环时用)
@property (nonatomic) CGFloat		scaleValue;		//当前显示值(当前值*缩放率)

- (MRPickerComponent *)setRangeWithMax:(NSInteger)max;
- (MRPickerComponent *)setRangeWithMax:(NSInteger)max withMin:(NSInteger)min;
- (MRPickerComponent *)setRangeWithFormat:(NSString *)format withMax:(NSInteger)max withMin:(NSInteger)min;

- (void)didSelect:(ComponentHandler)handler;
- (void)reloadComponent;

@end

#pragma mark -
//选择器==========================================================
@interface MRPickerView : UIView
{
	BOOL		_needsLayout;
}

- (instancetype)initWithBar:(UIView *)bar;

@property (nonatomic, readonly) NSMutableArray <MRPickerComponent *>	*components;

@property (nonatomic, readonly)	UIView			*barView;

@property (nonatomic) CGFloat		rowHeight;

- (MRPickerComponent *)firstComponent;
- (MRPickerComponent *)componentAtIndex:(NSUInteger)index;
- (MRPickerComponent *)componentWithTag:(NSInteger)tag;

- (MRPickerComponent *)addComponent;
- (MRPickerComponent *)addComponentWithLoop:(BOOL)loop;
- (MRPickerComponent *)addComponentWithLoop:(BOOL)loop withUnit:(NSString *)unit;

- (MRPickerComponent *)insertComponentWithLoop:(BOOL)loop atIndex:(NSUInteger)index;

- (void)insertComponent:(MRPickerComponent *)component atIndex:(NSUInteger)index;
- (void)replaceComponentAtIndex:(NSUInteger)index withComponent:(MRPickerComponent *)component;

- (void)removeAllComponents;
- (void)removeComponentAtIndex:(NSUInteger)index;
- (void)removeComponent:(MRPickerComponent *)component;

//日期组件（包含年、月、日，并自动管理）
@property (nonatomic) NSDate		*pickerDate;

- (void)addDateComponent;		//默认 1900 - 2099
- (void)addDateComponentWithMinYear:(NSInteger)minYear maxYear:(NSInteger)maxYear;

- (void)setPickerDate:(NSDate *)pickerDate animated:(BOOL)animated;

//区域组件（包含国家、省、市，并自动管理）
@property (nonatomic, readonly) NSUInteger	pickerCountry;
@property (nonatomic, readonly) NSUInteger	pickerProvince;
@property (nonatomic)			NSUInteger	pickerCity;

- (void)addRegionComponent;
- (NSString *)pickerRegion;
- (void)setPickerCity:(NSUInteger)pickerCity animated:(BOOL)animated;

@end
